//! Call pattern protocol definitions for homeserver user accounts.

use aspect_codec::prelude::*;
use aspect_ident::DirPackage;

/// Protocol definition for registering a username.
pub struct UserRegProto;

#[derive(Clone, Debug)]
pub struct UserRegRequest {
    /// Basic credentials.
    pub creds: UserCreds,

    /// Optional extra credential, maybe as secret password.
    pub extra_cred: Vec<u8>,
}

aspect_codec::inst_struct_codec! {
    UserRegRequest {
        creds: UserCreds,
        extra_cred: Vec<u8>,
    }
}

/// Username and password credentials.
#[derive(Clone, Debug)]
pub struct UserCreds {
    pub username: String,
    pub password: String,
}

aspect_codec::inst_struct_codec! {
    UserCreds {
        username: String,
        password: String,
    }
}

/// Protocol definition for adding devices to a user.
///
/// NB: This is not really secure, we just assume that if this is the first time
/// we're seeing this device identity that it's actually the user's device.  We
/// should also require a signature.
pub struct UserAddDeviceProto;

#[derive(Clone, Debug)]
pub struct UserAddDeviceRequest {
    pub creds: UserCreds,
    pub package: DirPackage,
}

aspect_codec::inst_struct_codec! {
    UserAddDeviceRequest {
        creds: UserCreds,
        package: DirPackage,
    }
}
